package copyengine.dataLayer.query.server
{
	import copyengine.utils.UUIDFactory;

	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public final class CEServerCommandQueryResultListener extends Mediator
	{
		private var rpcFunctionName:String;
		private var callBackFunction:Function;

		public function CEServerCommandQueryResultListener(_rpcFunctionName:String,
														   _callBackFunction:Function)
		{
			rpcFunctionName = _rpcFunctionName;
			callBackFunction = _callBackFunction;
			super(UUIDFactory.instance.generateUUID());
		}

		override final public function listNotificationInterests():Array
		{
			return [
				rpcFunctionName,
				];
		}

		override final public function handleNotification(notification:INotification):void
		{
			callBackFunction && callBackFunction(notification.getBody());
			callBackFunction = null;
			facade.removeMediator(getMediatorName());
		}

	}
}
